<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>链表实现</title>
</head>
<body>
    <script>
        //创建节点
        function Node(value){
            this.value = value;
            this.next = null;
        }
        function linkedList(arr){
            let head = new Node(arr[0]);
            let tail = head;
            for(var i=1;i<arr.length;i++){
                tail.next = new Node(arr[i]);
                tail = tail.next;
            }
            return head;
        }
        let link = linkedList([
            {
                name:'李小龙',
                value:1
            },
            {
                name:'李小龙2',
                value:2
            },
            {
                name:'李小龙3',
                value:3
            },
            {
                name:'李小龙4',
                value:4
            },
        ])
        let lxlarr =[]
        function revers1(head){
            lxlarr.push(head.value);
            if(head.next){
                revers1(head.next)
            }else {
                return;
            }
        }
        revers1(link)
        console.log(lxlarr)
        function revers(head){
            //遍历链表
            let arr =[];
            let p = head
            while(p){
                arr.push(p.value)
                p = p.next
            }
            return arr
        }
        let linkarr = revers(link);
        console.log(linkedList(linkarr))
    </script>
</body>
</html>